package com.modernyuanshiren;

public class Element implements IElement {
	private String name;
	private IPosition position;

	public Element(String name, int x, int y) {
		this.name = name;
		this.position = new Position(x, y);
	}

	public Element(IElement parent) {
		this.name = parent.getName();
		this.position = new Position(parent.getPosition().getX(), parent
				.getPosition().getY());
	}

	public Element(String name, int x) {
		this.name = name;
		this.position = new Position(x);
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public IPosition getPosition() {
		return position;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime
				* result
				+ ((position.getPoint() == null) ? 0 : position.getPoint()
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Element other = (Element) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (position == null) {
			if (other.position != null)
				return false;
		} else if (!position.getPoint().equals(other.position.getPoint()))
			return false;
		return true;
	}

}
